package com.future.message.Controller;

import com.future.message.Service.RelevantReportService;
import com.future.message.Utils.ResponseResult;
import com.future.message.pojo.RelevantReport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Api(tags = "填报关联")
@RequestMapping("/relevantReport")
public class RelevantReportController {
    @Resource
    RelevantReportService relevantReportService;

    @ApiOperation(value = "分配指标")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id",required = true)
            }
    )
    @Secured("ROLE_1")
    @PostMapping("/addRelevantReport")
    public ResponseResult addRelevantReport(Integer userId,Integer firstIndexId,Integer secondIndexId,Integer thirdIndexId) {
        return relevantReportService.addRelevantReport(userId, firstIndexId, secondIndexId, thirdIndexId);
    }

    @ApiOperation(value = "分配一级指标下所有指标")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id",required = true),
                    @ApiImplicitParam(name = "firstIndexId", value = "一级指标id",required = true)

            }
    )
    @PostMapping("/addRelevantReportByFirstIndexId")
    public ResponseResult addRelevantReportByFirstIndexId(Integer userId,Integer firstIndexId) {
        return relevantReportService.addRelevantReportByFirstIndexId(userId, firstIndexId);
    }

    @ApiOperation(value = "分配二级指标下所有指标")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id",required = true),
                    @ApiImplicitParam(name = "firstIndexId", value = "一级指标id",required = true),
                    @ApiImplicitParam(name = "secondIndexId", value = "二级指标id",required = true)
            }
    )
    @PostMapping("/addRelevantReportBySecondIndexId")
    public ResponseResult addRelevantReportBySecondIndexId(Integer userId,Integer firstIndexId,Integer secondIndexId) {
        return relevantReportService.addRelevantReportBySecondIndexId(userId, firstIndexId,secondIndexId);
    }


    @ApiOperation(value = "删除分配指标")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "relevantReportId", value = "id", required=true)
            }
    )
    @DeleteMapping("/deleteRelevantReport")
    @Secured("ROLE_1")
    public ResponseResult deleteRelevantReport(Integer relevantReportId) {
        return relevantReportService.deleteRelevantReport(relevantReportId);
    }


//    @ApiOperation(value = "遍历该用户下的指标")
//    @ApiImplicitParams(
//            {
//                    @ApiImplicitParam(name = "userId", value = "用户id",required = true)
//            }
//    )
//    @GetMapping("/findRelevantByUserId")
//    public ResponseResult findRelevantByUserId(Integer userId) {
//        return relevantReportService.findRelevantByUserId(userId);
//    }

//    @ApiOperation(value = "遍历所有分配的指标")
//    @GetMapping("/findAllRelevantReport")
//    public ResponseResult findAllRelevantReport() {
//        return relevantReportService.findAllRelevantReport();
//    }

    @ApiOperation(value = "根据id查找")
    @GetMapping("/findRelevantReportById")
    @Secured("ROLE_1")
    public ResponseResult findRelevantReportById(Integer relevantReportId) {
        return relevantReportService.findRelevantReportById(relevantReportId);
    }

    @ApiOperation(value = "批量删除分配指标")
    @DeleteMapping("/deleteRelevantList")
    @Secured("ROLE_1")
    public ResponseResult deleteRelevantList(Integer []relevantReportId) {
        return relevantReportService.deleteRelevantList(relevantReportId);
    }


    @ApiOperation(value = "遍历分配给该用户的一级指标")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id",required = true)
            }
    )
    @GetMapping("/findFirstIndexReport")
    public ResponseResult findFirstIndexReport(Integer userId) {
        return relevantReportService.findFirstIndexReport(userId);
    }


    @ApiOperation(value = "遍历分配给该用户的二级指标")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id",required = true),
                    @ApiImplicitParam(name = "firstIndexId", value = "一级指标id",required = true)
            }
    )
    @GetMapping("/findSecondIndexReport")
    public ResponseResult findSecondIndexReport(Integer userId,Integer firstIndexId) {
        return relevantReportService.findSecondIndexReport(userId,firstIndexId);
    }
    @ApiOperation(value = "遍历分配给该用户的三级指标")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id",required = true),
                    @ApiImplicitParam(name = "secondIndexId", value = "二级指标id",required = true)
            }
    )
    @GetMapping("/findThirdIndexReport")
    public ResponseResult findThirdIndexReport(Integer userId,Integer secondIndexId) {
        return relevantReportService.findThirdIndexReport(userId,secondIndexId);
    }


    @ApiOperation(value = "判断是否分配给用户该指标")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id",required = true),
                    @ApiImplicitParam(name = "thirdIndexId", value = "三级指标id",required = true)
            }
    )
    @GetMapping("/judgeOfRelevantReport")
    public ResponseResult judgeOfRelevantReport(Integer userId,Integer thirdIndexId) {
        return relevantReportService.judgeOfRelevantReport(userId,thirdIndexId);
    }


    @ApiOperation(value = "查询该用户需要填写多少个三级指标---共有几个指标")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id",required = true)
            }
    )
    @PostMapping("/countIndexNumberByUserId")
    public ResponseResult countIndexNumberByUserId(Integer userId) {
        return relevantReportService.countIndexNumberByUserId(userId);
    }


    @ApiOperation(value = "查询该用户完成了多少个三级指标---已完成几个指标")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id",required = true)
            }
    )
    @PostMapping("/countCompleteIndexNumberByUserId")
    public ResponseResult countCompleteIndexNumberByUserId(Integer userId) {
        return relevantReportService.countCompleteIndexNumberByUserId(userId);
    }

    @ApiOperation(value = "查询分配给该用户一级指标下的指标数量---该一级指标下总共有几个需要完成")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id",required = true),
                    @ApiImplicitParam(name = "firstIndexId", value = "一级指标id",required = true)
            }
    )
    @PostMapping("/countIndexNumberByUserIdAndIndexId")
    public ResponseResult countIndexNumberByUserIdAndIndexId(Integer userId,Integer firstIndexId) {
        return relevantReportService.countIndexNumberByUserIdAndIndexId(userId,firstIndexId);
    }

    @ApiOperation(value = "查询分配给该用户一级指标下的完成的指标数量---该一级指标下完成了几个指标")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id",required = true),
                    @ApiImplicitParam(name = "firstIndexId", value = "一级指标id",required = true)
            }
    )
    @PostMapping("/countCompleteIndexNumberByUserIdIndexId")
    public ResponseResult countCompleteIndexNumberByUserIdIndexId(Integer userId,Integer firstIndexId) {
        return relevantReportService.countCompleteIndexNumberByUserIdIndexId(userId,firstIndexId);
    }


    @ApiOperation(value = "判断是否用户是否填报")
    @PostMapping("/judgeOfReport")
    public ResponseResult judgeOfReport(Integer relevantReportId) {
        return relevantReportService.judgeOfReport(relevantReportId);
    }

    @ApiOperation(value = "判断二级指标下完成情况,0-->一个没完成,1-->完成一部分,2-->全部完成")
    @PostMapping("/findThirdIndexListBySecondIndexList")
    public ResponseResult findThirdIndexListBySecondIndexList(Integer secondIndexId) {
        return relevantReportService.findThirdIndexListBySecondIndexList(secondIndexId);
    }

    @ApiOperation(value = "判断二级指标下的完成率")
    @PostMapping("/findSecondCompleteRate")
    public ResponseResult findSecondCompleteRate(Integer secondIndexId) {
        return relevantReportService.findSecondCompleteRate(secondIndexId);
    }

    @ApiOperation(value = "查看等级指标分配给的用户")
    @PostMapping("/findUserByOfDistribution")
    public ResponseResult findUserByOfDistribution(Integer grade, Integer indexId) {
        return relevantReportService.findUserByOfDistribution(grade, indexId);
    }


    @ApiOperation(value = "删除某用户的该等级下填报关联")
    @DeleteMapping("/deleteReportsByIndexIdAndUserId")
    public ResponseResult deleteReportsByIndexIdAndUserId(Integer indexGrade, Integer indexId,Integer userId) {
        return relevantReportService.deleteReportsByIndexIdAndUserId(indexId, userId,indexGrade);
    }



}
